package com.wjw.controller.test;

import com.wjw.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Calendar;

//重温springboot
//-----------------原始的spring框架中创建对象的注解-----------------
//@Component    通用对象创建注解,
//@Controller   创建控制器的注解
//@Service      创建service层的注解
//@Repository   创建dao层的注解

//-------------------------引用类型属性注入-------------------------
//@Autowired    spring框架提供,默认按照类型注入
//@Qualifier("demoServiceImpl123")不按类型注入,按名称注,如在DemoServiceImpl类上使用@Service("demoServiceImpl123")
//@Resources    JavaEE规范,默认按照名称注入,如果没找到,则按类型注入
//-----------------------------------------------------------------

@RestController
public class DemoController {

    @Autowired //自动按照类型注入
    @Qualifier("demoServiceImpl123")//不按类型注入,按名称注入
    private DemoService demoService;

    //BeanConfig中配置的SimpleDateFormat
    @Autowired //自动按照类型注入
    private SimpleDateFormat sdf;

    @GetMapping("/getTime")
    public String getTime(){
        Calendar calendar = Calendar.getInstance();
        String format = sdf.format(calendar.getTime());
        String say = demoService.say();
        System.out.println("format:"+format);
        System.out.println("say:"+say);
        return "当前日期是：" + format;
    }

    @GetMapping("/sayHello11")
    public String sayHello(){
        System.out.println("sayHello11");
        return "sayHello11";
    }
}
